import { registerMicroApps, start, createStore } from '../../micro/index'
import  { loading } from  '../store'

// 全局store测试
const store = createStore();
window.store = store;
const storeData = store.getStore();

store.subscribe((newVal,oldVal) => {
  console.log('newVal,oldVal==========', newVal,oldVal)
})

store.update({
  ...storeData,
  a: 1
})


// 微前端方法
export const registerApp = (list) => {
  // 注册到微前端框架
  registerMicroApps(list, {
    // 主应用生命周期： 为什么要定义成数组？
    beforeLoad: [
      () => {
        console.log('micro开始加载')
        loading.changeLoading(true)
      } 
    ],
    mounted: [
      () => {
        console.log('micro渲染完成')
        loading.changeLoading(false)
      } 
    ],
    destoryed: [
      () => {
        console.log('micro卸载完成')
      } 
    ]
  });

  // 启动微前端框架
  start();
}